<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%><%@include file="/web/base/header.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
	<fieldset class="layui-elem-field">
		<legend>部门信息</legend>
		<div class="layui-field-box">
			<form class="layui-form">
				<label class="layui-form-label">科室名字</label>
				<div class="layui-inline">
					<input type="text" name="departmentname" placeholder="请输入科室名字"
						autocomplete="off" class="layui-input">
				</div>
				<br /> <label class="layui-form-label">科室地址</label>
				<div class="layui-inline">
					<input type="text" name="departmentaddress" placeholder="请输入科室地址"
						autocomplete="off" class="layui-input">
				</div>
				&nbsp;&nbsp; <input id="sele" type="submit" class="layui-btn" lay-submit
					lay-filter="select" value="查找" /> 
					<input class="layui-btn" id="tanadd" value="添加">
				
<!-- 				<input name="action" type="hidden" value="select" /> -->
				<input name="action" type="hidden" value="page"/>
				<input name="curr" type="hidden" value="1"/>
				<input name="limit" type="hidden" value="10"/>
			</form>

		</div>
		<table class="layui-table">

			<thead>
				<tr>
					<th>序号</th>
					<th>科室名称</th>
					<th>科室地址</th>
					<th>科室电话</th>
					<th>科室人数</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="departmenttbody"></tbody>
		</table>
		
		<div id="page"></div>


	</fieldset>
	<script type="text/html" id="addhtml">
		<form class="layui-form">
						<div class="layui-form-item">
							<label class="layui-form-label">科室名字</label>
							<div class="layui-inline">
								<input type="text" name="departmentname" required lay-verify="required" placeholder="请输入科室名字" autocomplete="off"
									class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">科室地址</label>
							<div class="layui-inline">
								<input type="text" name="departmentaddress" required lay-verify="required" placeholder="请输入科室地址" autocomplete="off"
									class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">科室电话</label>
							<div class="layui-inline">
								<input type="text" name="departmenttel" required lay-verify="required" placeholder="请输入科室电话" autocomplete="off"
									class="layui-input">
							</div>
						</div>

						
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="add">提交</button>
								<button type="reset" class="layui-btn layui-btn-primary">重置</button>
							</div>
						</div>
						<input type="hidden" name="action" value="add"/>

					</form>

	</script>
	<script type="text/html" id="updhtml">
		<form class="layui-form" lay-filter="updform">
						<div class="layui-form-item" >
							<label class="layui-form-label">科室名字</label>
							<div class="layui-inline">
								<input type="text" name="departmentname" required lay-verify="required" placeholder="请输入科室名字" autocomplete="off"
									class="layui-input layui-disabled">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">科室地址</label>
							<div class="layui-inline">
								<input type="text" name="departmentaddress" required lay-verify="required" placeholder="请输入科室地址" autocomplete="off"
									class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">科室电话</label>
							<div class="layui-inline">
								<input type="text" name="departmenttel" required lay-verify="required" placeholder="请输入科室电话" autocomplete="off"
									class="layui-input">
							</div>
						</div>

						
						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn" lay-submit lay-filter="upd">提交</button>
								<button type="reset" class="layui-btn layui-btn-primary">重置</button>
							</div>
						</div>
						
						<input type="hidden" name="action" value="upd"/>

					</form>

	</script>

	<script type="text/javascript">
	
	
		$("#tanadd").click(tan);
		formon('submit(select)',base.app+'/DepartmentServlet','json',
			function(data2){
			var tar=JSON.stringify(data2);
			resp = JSON.parse(tar);
			setpage("page",resp["count"],$("input[name='curr']").val(),$("input[name='limit']").val(),
					function(obj,first){
				$("input[name='curr']").val(obj.curr);
				$("input[name='limit']").val(obj.limit);
				if(!first){
					f5("input[value='查找']");
				}
			});
            var aa = resp["list"];
				var html="";
				$.each(aa,function(i,dom){
					var name=dom.departmentName?dom.departmentName:'';
					var address=dom.departmentAddress?dom.departmentAddress:'';
					var tel=dom.departmentTel?dom.departmentTel:'';
					var nums=dom.doctorNums?dom.doctorNums:'0';
					
					html+="<tr>"+
						"<td>"+ ++i +"</td>"+
						"<td>"+name+"</td>"+
						"<td>"+address+"</td>"+
						"<td>"+tel+"</td>"+
						"<td>"+nums+"</td>"+
						"<td>"+
						"<a href='javascript:del(\"" + name + "\");' class='layui-btn'>删除</a>"+
						"<a href='javascript:tanupd(\"" + name + "\");' class='layui-btn'>修改</a>"+
						
						"</td></tr>";
				})
				$("#departmenttbody").html(html);
				
		})
		
		f5("input[value='查找']");
					
		function tan() {
// 			openLayer("/web/page/department/add.jsp",refresh);
			layer.open({
				type: 1,
				area: ['400px', '400px'],
				content: $("#addhtml").html(),
				title: "添加",
				success: function(index) {
					form.render();
					formon('submit(add)',base.app+'/DepartmentServlet','text',
						function(data2){
							if("1"==data2){
								alert("添加成功");
								closeThis();
								f5("input[value='查找']");
							}
							if("0"==data2){
								alert("添加失败");
							}
							if("2"==data2){
								alert("请输入数据");
							}
							if("3"==data2){
								alert("部门已存在")
							}
						})
					
				}
			});
			
		}
		
		function del(name){
			if(confirm("确定删除")){
				var data={departmentname:name,action:"del"};
				ajax1(data,base.app+'/DepartmentServlet',"text",function(data){
					if("1"==data){
						alert("删除成功");
					}else{
						alert("删除失败");
					}
				})
				f5("input[value='查找']");
			}
		}
		
		function tanupd(name){
			layer.open({
				type: 1,
				area: ['400px', '400px'],
				content: $("#updhtml").html(),
				title: "修改",
				success: function(index) {
					var data1={departmentname:name,action:"selectmodel"};
					ajax1(data1,base.app+'/DepartmentServlet','json',
							function(data3){
								var tar=JSON.stringify(data3);
								resp = JSON.parse(tar);
			            		var aa = resp["selectmodel"];
								var indata={
										departmentname:aa.departmentName,
										departmentaddress:aa.departmentAddress,
										departmenttel:aa.departmentTel
								};
								form.val("updform", indata);
								
					});
					
					form.render();
					formon('submit(upd)',base.app+'/DepartmentServlet','text',
						function(data2){
							if("1"==data2){
								alert("修改成功");
								f5("input[value='查找']");
								closeThis();
							}
							if("2"==data2){
								alert("请输入数据");
							}
							if("0"==data2){
								alert("修改失败");
							}
						})
						
				}
			});
			
		}
		
	</script>
</body>
</html>